package com.isoftstone.project.facilities.underdata.controller;

import com.isoftstone.common.utils.ExcelUtil;
import com.isoftstone.framework.controller.BaseController;
import com.isoftstone.framework.domain.Page;
import com.isoftstone.framework.domain.PageData;
import com.isoftstone.framework.domain.Tidings;
import com.isoftstone.project.facilities.underdata.domain.MonitorUnderParameter;
import com.isoftstone.project.facilities.underdata.service.IMonitorUnderParameterService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 井下分站参数设置Controller
 *
 * @author guoX
 * @date 2021-02-02
 */
@Controller
@RequestMapping("/facilities/underdata")
public class MonitorUnderParameterController extends BaseController {
    private String prefix = "facilities/underdata";

    @Autowired
    private IMonitorUnderParameterService monitorUnderParameterService;

    @RequiresPermissions("parameter:underdata:view")
    @GetMapping()
    public String underdata() {
        return prefix + "/underdata_list";
    }

    /**
     * 查询井下分站参数设置列表
     */
    @RequiresPermissions("parameter:underdata:list")
    @PostMapping("/monitorUnderParameterlistPage")
    @ResponseBody
    public Object getmonitorUnderParameterlistPage(Page page) {
        PageData pd = this.getPageData();
        page.setPd(pd);
        List<MonitorUnderParameter> list = monitorUnderParameterService.getMonitorUnderParameterlistPage(page);
        return Tidings.success(page.getTotalResult(), list);
    }


    /**
     * 导出井下分站参数设置列表
     */
    @RequiresPermissions("parameter:underdata:export")
    @PostMapping("/exportMonitorUnderParameter")
    @ResponseBody
    public Object exportMonitorUnderParameter(Page page) {
        PageData pd = this.getPageData();
        page.setPd(pd);
        page.setEntityOrField(false);
        List<MonitorUnderParameter> list = monitorUnderParameterService.getMonitorUnderParameterlistPage(page);
        ExcelUtil<MonitorUnderParameter> util = new ExcelUtil<MonitorUnderParameter>(MonitorUnderParameter. class);
        return util.exportExcel(list, "underdata");
    }

    /**
     * 新增井下分站参数设置
     */
    @GetMapping("/addMonitorUnderParameter")
    public String addMonitorUnderParameter() {
        return prefix + "/underdata_add";
    }


    /**
     * 新增保存井下分站参数设置
     */
    @RequiresPermissions("parameter:underdata:add")
    @PostMapping("/addMonitorUnderParameter")
    @ResponseBody
    public Object insertMonitorUnderParameter(MonitorUnderParameter monitorUnderParameter) {
        monitorUnderParameterService.insertMonitorUnderParameter(monitorUnderParameter);
        return Tidings.success();

    }

    /**
     * 修改井下分站参数设置
     */
    @GetMapping("/toEditMonitorUnderParameter")
    public String toEditMonitorUnderParameter(String comid, ModelMap mmap) {
        MonitorUnderParameter monitorUnderParameter =monitorUnderParameterService.getMonitorUnderParameterById(comid);
        mmap.put("monitorUnderParameter", monitorUnderParameter);
        return prefix + "/underdata_edit";
    }

    /**
     * 修改保存井下分站参数设置
     */
    @RequiresPermissions("parameter:underdata:edit")
    @PostMapping("/updateMonitorUnderParameter")
    @ResponseBody
    public Object updateMonitorUnderParameter(MonitorUnderParameter monitorUnderParameter) {
        monitorUnderParameterService.updateMonitorUnderParameter(monitorUnderParameter);
        return Tidings.success();
    }

    /**
     * 删除井下分站参数设置
     */
    @RequiresPermissions("parameter:underdata:remove")
    @PostMapping("/deleteMonitorUnderParameter")
    @ResponseBody
    public Object deleteMonitorUnderParameter(String comid) {
        monitorUnderParameterService.deleteMonitorUnderParameterByIds(comid);
        return Tidings.success();
    }

}
